package com.zd.springcloud.provider.controller;

import com.zd.springcloud.domain.Good;
import com.zd.springcloud.provider.mapper.GoodMapper;
import com.zd.springcloud.provider.service.GoodService;
import com.zd.springcloud.provider.tccaction.GoodAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/good")
public class GoodController {

    @Autowired
    GoodAction goodAction;

    @Autowired(required = false)
    GoodMapper goodMapper;

    @PutMapping("/reduceStock")
    public String reduceStock(@RequestParam("num") int num, @RequestParam("goodId") Long goodId){
        goodAction.reduceStock(null,num,goodId);
        return "success";
    }


    @PutMapping("/getGoodInfoById/{goodId}")
    public Good getGoodInfoById(@PathVariable("goodId") Long goodId){
        return goodMapper.findGoodById(goodId);

    }

}
